package org.thomias.loggertest;

import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.StreamHandler;

public class YT {

	private static Logger logger;
	private static StreamHandler fh;

	public static void debug(String msg) {
		log(Level.INFO, msg + "\n");
	}

	private static void log(Level level, String msg) {
		LogRecord r = new LogRecord(level, msg);
		Object[] parameters = new Object[2];
		parameters[0] = new Throwable();
		parameters[1] = Thread.currentThread();
		r.setParameters(parameters);
		logger.log(r);
		System.out.flush();
		fh.flush();
		System.out.flush();
	}

	public static void init() {
		fh = new StreamHandler(System.out, new YTFormatter());
		logger = Logger.getLogger("yannis");
		logger.setUseParentHandlers(false);
		logger.addHandler(fh);
	}
}
